package com.xsomnus.open.imv2.foo.client.console;

import com.xsomnus.open.imv2.protocol.request.LoginRequestPacket;
import io.netty.channel.Channel;

import java.util.Scanner;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/26 0026 9:53
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
public class LoginConsoleCommand implements ConsoleCommand {

    @Override
    public void exec(Scanner scanner, Channel channel) {
        LoginRequestPacket requestPacket = new LoginRequestPacket();
        System.out.print("输入登陆的用户名: ");
        requestPacket.setUsername(scanner.nextLine());
        requestPacket.setPassword("pwd");

        // 发送登陆的数据包
        channel.writeAndFlush(requestPacket);
        waitForLoginResponse();
    }

    private static void waitForLoginResponse() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
